package com.pain.scaffold.admin.service.mq;

import com.pain.scaffold.common.model.core.R;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Slf4j
@Service
@RequestMapping("/mq")
public class Provider {

    @Resource
    RocketMQTemplate rocketMQTemplate;

    @ApiOperation(value = "rocketMq test", notes = "")
    @PostMapping("/test")
    public R testRocketMq(){
        String msg = "hello";
        rocketMQTemplate.asyncSend("topic1", msg , new SendCallback() {
            @Override
            public void onSuccess(SendResult var1) {
                // 成功回调
                System.out.printf("async onSuccess SendResult=%s %n", var1);
            }
            @Override
            public void onException(Throwable var1) {
                // 失败回调
                System.out.printf("async onException Throwable=%s %n", var1);
            }
        });
        return R.ok();
    }


}
